package com.jwj.testback.recordsheet.controller;


import com.jwj.testback.recordsheet.pojo.Recordsheet;
import com.jwj.testback.recordsheet.service.RecordsheetService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JWJ
 * @since 2021-12-17
 */
@Controller
@RequestMapping("/recordsheet")
public class RecordsheetController {

    @Resource
    private RecordsheetService recordsheetService;


    //添加表
    @ApiOperation(value = "添加表")
    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public String add(String databaseName,String tableName,String fieldTime,String customField,Integer type,Integer endType,String customStart, String customEnd){
        String add = recordsheetService.add(databaseName, tableName,fieldTime, customField, type, endType, customStart, customEnd);
        return add;
    }

    //添加表
//    @ApiOperation(value = "添加表")
//    @ResponseBody
//    @CrossOrigin
//    @RequestMapping(value = "/add",method = RequestMethod.POST)
//    public String add(String databaseName,String tableName,String fieldTime,Integer type,Integer sure,Integer endType){
//        String add = recordsheetService.add(databaseName, tableName,fieldTime, type, sure, endType);
//        return add;
//    }

    @ApiOperation(value = "分页数据")
    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/page",method = RequestMethod.GET)
    public List<Long> PagData(String databaseName,String tableName,String tableIdName,Integer offset,Integer pageSize){
        List<Long> list = recordsheetService.PagData(databaseName,tableName, tableIdName, offset, pageSize);
        return list;
    }

//    @ApiOperation(value = "删除测试")
//    @ResponseBody
//    @CrossOrigin
//    @RequestMapping(value = "/de",method = RequestMethod.GET)
//    public Boolean delSure(String databaseName,String tableName,String tableIdName){
//        recordsheetService.delSure(databaseName, tableName, tableIdName);
//        return true;
//    }

    @ApiOperation(value = "显示所有记录")
    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/showRecord",method = RequestMethod.GET)
    public List<Recordsheet> showRecord(){
        List<Recordsheet> list = recordsheetService.showRecord();
        return list;
    }

//    @ApiOperation(value = "删除一条记录")
//    @ResponseBody
//    @CrossOrigin
//    @RequestMapping(value = "/delRecord",method = RequestMethod.POST)
//    public int delRecord(Long id){
//        int i = recordsheetService.delRecord(id);
//        return i;
//    }
}

